﻿using _111.Models;
using Azure;
using Azure.Core;
using Dapper;
using guidHelper;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc.RazorPages;
using MyDapperApi.Models;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using Org.BouncyCastle.Asn1.Ocsp;
using QYWXUpdate.DataModel;
using QYWXUpdate.DataModel.QueueFront;
using System.Data;
using System.Net.Sockets;
using System.Text;
using static MyDapperApi.Services.DateBaseService;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace MyDapperApi.Services;

public class QueueFrontService : IQueueFrontService
{
    private readonly IConfiguration _configuration;
    private readonly IDateBaseService _dateBaseService;
    private readonly IHttpClientFactory _httpClientFactory;

    // 通过依赖注入获取配置，从而读取连接字符串
    public QueueFrontService(IConfiguration configuration, IDateBaseService dateBaseService, IHttpClientFactory httpClientFactory)
    {
        _configuration = configuration;
        _dateBaseService = dateBaseService;
        _httpClientFactory = httpClientFactory;
    }

    // 获取数据库连接
    private IDbConnection CreateConnection()
    {
        return new MySqlConnection(_configuration.GetConnectionString("DefaultConnection"));
    }
    /// <summary>
    /// 获取排队号码
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    public async Task<CommonResponse> AddQueue(AddQueueFrontRequest request)
    {
        var result = new CommonResponse();

        if (request.ConsumerNum <= 2)
        {
            request.Type = "A";
        }
        if (request.ConsumerNum > 2 && request.ConsumerNum <= 4)
        {
            request.Type = "B";
        }
        if (request.ConsumerNum > 4)
        {
            request.Type = "C";
        }

        using var connection = CreateConnection();
        var sql = "SELECT * FROM sgtq_front_queue_detail where shop_id = @ShopId and date = @Date order by created_on desc";
        var checkSql = "SELECT * FROM sgtq_front_queue_detail where is_deleted = 0 ";
        var sqlBuilder = new SqlBuilder();
        var date = ToolHelper.ConvertDateTimeToInt(DateTime.Now);
        if (!string.IsNullOrEmpty(request.Phone))
        {
            sqlBuilder.Add(" and phone = @Phone ", "Phone", request.Phone);
        }
        var userId = string.Empty;
        if (!string.IsNullOrEmpty(request.UserId))
        {
            userId = AesCbcHelper.Decrypt(request.UserId, System.Text.Encoding.Default.GetBytes("xshAesKey1234567"), System.Text.Encoding.Default.GetBytes("1234567890abcdef"));
            sqlBuilder.Add(" and user_id = @UserId ", "UserId", userId);
        }
        sqlBuilder.Add(" and shop_id = @ShopId ", "ShopId", request.ShopId);
        sqlBuilder.Add(" and date = @Date ", "Date", date);

        var updateSqlModel = new SgtqQueueFrontDetailModel()
        {
            Id = ToolHelper.GUIDTO16(),
            ShopId = request.ShopId,
            CreatedOn = DateTime.Now,
            Status = 0,
            IsDeleted = 0
        };
        var res = new SgtqQueueFrontDetailEntity();
        var checkRes = new SgtqQueueFrontDetailEntity();

        checkRes = await _dateBaseService.QueryFirstOrDefaultAsync<SgtqQueueFrontDetailEntity>(checkSql, sqlBuilder);

        if (checkRes != null)
        {
            result.SetError("重复取号");
            return result;
        }

        res = await connection.QueryFirstOrDefaultAsync<SgtqQueueFrontDetailEntity>(sql, new
        {
            ShopId = request.ShopId,
            Date = date
        });
        if (res != null)
        {
            updateSqlModel.Code = res.Code + 1;
        }
        else
        {
            updateSqlModel.Code = 1;
        }
        updateSqlModel.Date = date;
        updateSqlModel.Type = request.Type;
        updateSqlModel.Phone = request.Phone ?? string.Empty;
        updateSqlModel.UserId = userId;
        updateSqlModel.UserName = request.UserName ?? string.Empty;
        updateSqlModel.AlarmTimes = 0;
        updateSqlModel.ConsumerNum = request.ConsumerNum;
        var insertRes = await CreateQueue(updateSqlModel,connection);
        if (!string.IsNullOrEmpty(request.UserId))
            await SwitchMsg(request.UserId, 0);

        result.SetSuccess(updateSqlModel);
        return result;

    }
    /// <summary>
    /// 基础插入方法
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    public async Task<int> CreateQueue(SgtqQueueFrontDetailModel request, IDbConnection connection)
    {
        //using var connection = CreateConnection();
        var sql = "INSERT INTO sgtq_front_queue_detail (id, code,consumer_num, created_on, shop_id, status, date, type, phone, user_id,user_name, alarm_times, is_deleted) VALUES (@Id, @Code,@ConsumerNum, @CreatedOn, @ShopId, @Status, @Date, @Type, @Phone, @UserId,@UserName, @AlarmTimes, @IsDeleted)";
        return await connection.ExecuteAsync(sql, request);
    }
    /// <summary>
    /// 删除号码
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    public async Task<CommonResponse> DeleteQueueCode(DelQueueFrontRequest request)
    {
        var result = new CommonResponse();

        var entity = new SgtqQueueFrontDetailEntity();
        result = await GetQueue(new IdRequest() { Id = request.Id });

        if (result.Success)
        {
            entity = (SgtqQueueFrontDetailEntity)result.data;
            await SwitchMsg(entity.User_Id, request.Status, true);
        }
        else
        {
            result.SetError("数据错误");
            return result;
        }

        using var connection = CreateConnection();
        var sql = "UPDATE sgtq_front_queue_detail SET is_deleted = 1, status = @Status WHERE Id = @Id";
        var res = await connection.ExecuteAsync(sql, new
        {
            Id = request.Id,
            Status = request.Status,
        });

        if (res == 1)
        {
            result.SetSuccess();
        }
        else
        {
            result.SetError();
        }

        return result;
    }
    /// <summary>
    /// 用户查看排队号码
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    public async Task<CommonResponse> PagingQueueByConsumer(PagingQueueFrontByConsumerRequest request)
    {
        var result = new CommonResponse();
        using var connection = CreateConnection();
        var date = ToolHelper.ConvertDateTimeToInt(DateTime.Now);
        var sqlExt = "SELECT * FROM sgtq_front_queue_detail where is_deleted = 0 ";
        var sqlExtBuilder = new SqlBuilder();
        if (!string.IsNullOrEmpty(request.UserId))
        {
            var userId = AesCbcHelper.Decrypt(request.UserId, System.Text.Encoding.Default.GetBytes("xshAesKey1234567"), System.Text.Encoding.Default.GetBytes("1234567890abcdef"));
            sqlExtBuilder.Add(" and user_id = @UserId", "UserId", userId);
        }
        if (!string.IsNullOrEmpty(request.Phone)) sqlExtBuilder.Add(" and phone = @Phone", "Phone", request.Phone);
        sqlExtBuilder.Add(" and date = @Date ", "Date", date);
        sqlExtBuilder.AddOrderBy(" order by created_on desc ");

        var addqueueRes = await _dateBaseService.QueryFirstOrDefaultAsync<SgtqQueueFrontDetailEntity>(sqlExt, sqlExtBuilder);

        if (addqueueRes == null)
        {
            result.SetError();
            return result;
        }

        var sql = "SELECT count(*) FROM sgtq_front_queue_detail where shop_id = @ShopId and date = @Date and code < @Code and is_deleted = 0 and status <> 5";
        var fronum = await connection.QueryFirstOrDefaultAsync<int>(sql, new
        {
            ShopId = addqueueRes.Shop_Id,
            Code = addqueueRes.Code,
            Date = date,
            Type = addqueueRes.Type
        });

        var queueRes = new AddQueueFrontResponse()
        {
            Id = addqueueRes.Id,
            ShopId = addqueueRes.Shop_Id,
            Code = addqueueRes.Type + addqueueRes.Code,
            Status = addqueueRes.Status,
            Num = fronum,
            Time = addqueueRes.Created_On,
        };
        result.SetSuccess(queueRes);

        return result;
    }
    /// <summary>
    /// 获取排队信息
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    public async Task<CommonResponse> PagingQueue(PagingQueueFrontRequest request)
    {
        var result = new CommonResponse();
        using var connection = CreateConnection();

        var sqlExt = @$"SELECT 
            main.Id,
            CONCAT(main.Type, main.Code) AS Code,
            main.consumer_num as `ConsumerNum`,
            main.shop_id as `ShopId`,
            main.Status,
            main.Date,
            main.Phone,
            main.user_id as `UserId`,
            main.user_name as `UserName`,
            main.alarm_times as `AlarmTimes`,
            main.created_On as `CreatedOn`,
            main.front_count as `OldCount`,
            -- 计算前方剩余桌数：使用code < 当前记录code的条件
            (SELECT COUNT(*) 
             FROM sgtq_front_queue_detail sub
             WHERE sub.shop_id = main.shop_id
             AND sub.date = main.date
             AND sub.code < main.code
             AND sub.is_deleted = 0
             AND sub.status <> 5) AS `FrontCount`
        FROM sgtq_front_queue_detail main where 1 = 1 and is_deleted = @IsDeleted ";

        var sqlNum = @$"SELECT count(*)
FROM sgtq_front_queue_detail where 1 = 1 and is_deleted = @IsDeleted ";

        if (!string.IsNullOrEmpty(request.ShopId))
        {
            sqlExt += "and shop_id = @ShopId ";
            sqlNum += "and shop_id = @ShopId ";
        }
        if (request.Date.HasValue)
        {
            sqlExt += "and date = @Date ";
            sqlNum += "and date = @Date ";
        }
        if (request.Status.HasValue)
        {
            sqlExt += "and status = @Status ";
            sqlNum += "and status = @Status ";
        }
        //if (!string.IsNullOrEmpty(request.Type))
        //{
        //    sqlExt += "and type = @Type ";
        //    sqlNum += "and type = @Type ";
        //}
        if (request.IsDeleted.HasValue && request.IsDeleted == 1)
        {
            request.IsDeleted = 1;
        }
        else
        {
            request.IsDeleted = 0;
        }

        var resNum = await connection.QueryFirstOrDefaultAsync<int>(sqlNum, request);

        var resultList = new List<PagingQueueFrontResponse>();

        if (resNum > 0)
        {
            sqlExt += "order by created_on desc ";
            sqlExt += $"limit {(request.PageIndex - 1) * request.PageSize},{request.PageSize} ";

            var addqueueRes = await connection.QueryAsync<PagingQueueFrontResponse>(sqlExt, request);

            foreach (var item in addqueueRes)
            {
                if (!item.OldCount.HasValue || item.OldCount.Value != item.FrontCount)
                {
                    var entity = new SgtqQueueFrontDetailEntity()
                    {
                        Id = item.Id,
                        Front_Count = item.FrontCount
                    };

                    result = await _dateBaseService.UpdateSpecifiedFields(entity);
                    if (result.Success)
                    {
                        if (item.FrontCount > 0 && item.FrontCount <= 3 && !string.IsNullOrEmpty(item.UserId))
                        {
                            item.UserId = AesCbcHelper.Encrypt(item.UserId, System.Text.Encoding.Default.GetBytes("xshAesKey1234567"), System.Text.Encoding.Default.GetBytes("1234567890abcdef"));
                            await SwitchMsg(item.UserId, 6, false, item);
                        }
                    }
                }
            }

            if (addqueueRes == null)
            {
                result.SetError();
                return result;
            }

            resultList = addqueueRes.ToList();
        }

        var response = new
        {
            Total = resNum,
            rows = resultList
        };

        result.SetSuccess(response);

        return result;
    }
    /// <summary>
    /// 获取排队信息-看板
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    public async Task<CommonResponse> PagingQueueForBoard(PagingQueueFrontRequest request)
    {
        var result = request.Check();
        using var connection = CreateConnection();

        var sqlExt = @$"SELECT 
            main.Id,
            CONCAT(main.Type, main.Code) AS Code,
            main.Status
        FROM sgtq_front_queue_detail main where 1 = 1 and is_deleted = @IsDeleted ";

        var sqlNum = @$"SELECT count(*)
FROM sgtq_front_queue_detail where 1 = 1 and is_deleted = @IsDeleted ";

        if (!string.IsNullOrEmpty(request.ShopId))
        {
            sqlExt += "and shop_id = @ShopId ";
            sqlNum += "and shop_id = @ShopId ";
        }
        if (!request.Date.HasValue)
        {
            request.Date = ToolHelper.ConvertDateTimeToInt(DateTime.Now);
        }
        sqlExt += "and date = @Date ";
        sqlNum += "and date = @Date ";
        if (request.Status.HasValue)
        {
            sqlExt += "and status = @Status ";
            sqlNum += "and status = @Status ";
        }
        if (!string.IsNullOrEmpty(request.Type))
        {
            sqlExt += "and type = @Type ";
            sqlNum += "and type = @Type ";
        }
        if (request.IsDeleted.HasValue && request.IsDeleted == 1)
        {
            request.IsDeleted = 1;
        }
        else
        {
            request.IsDeleted = 0;
        }

        var resNum = await connection.QueryFirstOrDefaultAsync<int>(sqlNum, request);

        var resultList = new List<PagingFrontQueueforBoardShowResponse>();

        if (resNum > 0)
        {
            sqlExt += "order by created_on desc ";
            sqlExt += $"limit {(request.PageIndex - 1) * request.PageSize},{request.PageSize} ";

            var addqueueRes = await connection.QueryAsync<PagingFrontQueueforBoardResponse>(sqlExt, request);

            if (addqueueRes == null)
            {
                result.SetError();
                return result;
            }

            foreach (var item in addqueueRes)
            {
                var temp = new PagingFrontQueueforBoardShowResponse()
                {
                    Id = item.Id,
                    Code = item.Code,
                    TableNumber = item.TableNumber,
                    Status = GetResStatus(item.Status),
                };
                resultList.Add(temp);
            }
        }

        var response = new
        {
            Total = resNum,
            rows = resultList
        };

        result.SetSuccess(response);

        return result;
    }

    public string GetResType(string type)
    {
        switch (type)
        {
            case "A":
                return "小桌";
                break;
            case "B":
                return "中桌";
                break;
            case "C":
                return "大桌";
                break;
            default:
                return "error";
        }

    }

    public string GetResStatus(int type)
    {
        switch (type)
        {
            case 0:
                return "排队中";
                break;
            case 1:
                return "叫号中";
                break;
            default:
                return "error";
        }

    }

    /// <summary>
    /// 用于统计这家店目前今日完成和叫号中的号码
    /// </summary>
    /// <returns></returns>
    public async Task<CommonResponse> PagingQueueDetail(PagingQueueDetailRequest request)
    {
        var result = new CommonResponse();

        using var connection = CreateConnection();

        var sqlNum = @$"SELECT 
  SUM(CASE WHEN `status` = 1 AND `is_deleted` = 0 THEN 1 ELSE 0 END) AS `Asking`,
  SUM(CASE WHEN `is_deleted` = 1 THEN 1 ELSE 0 END) AS `IsFinished`
FROM `sgtq_front_queue_detail`
WHERE `date` = @Date ";

        if (!string.IsNullOrEmpty(request.ShopId))
        {
            sqlNum += "and shop_id = @ShopId ";
        }

        var sqlRequest = new
        {
            Date = ToolHelper.ConvertDateTimeToInt(DateTime.Now),
            ShopId = request.ShopId,
        };

        var resNum = await connection.QueryFirstOrDefaultAsync<PagingQueueDetailResponse>(sqlNum, sqlRequest);

        result.SetSuccess(resNum);

        return result;
    }
    /// <summary>
    /// 用于获取单个数据的详细信息
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    public async Task<CommonResponse> GetQueue(IdRequest request)
    {
        var result = new CommonResponse();
        using var connection = CreateConnection();
        var sql = "Select * from sgtq_front_queue_detail where id = @Id";
        var res = new SgtqQueueFrontDetailEntity();
        res = await connection.QueryFirstOrDefaultAsync<SgtqQueueFrontDetailEntity>(sql, request);
        res.User_Id = AesCbcHelper.Encrypt(res.User_Id, System.Text.Encoding.Default.GetBytes("xshAesKey1234567"), System.Text.Encoding.Default.GetBytes("1234567890abcdef"));

        if (res == null)
        {
            result.SetError("找不到对应的数据");
            return result;
        }

        result.SetSuccess(res);
        return result;
    }
    /// <summary>
    /// 删除号码
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    public async Task<CommonResponse> Asking(IdRequest request)
    {
        var result = new CommonResponse();
        using var connection = CreateConnection();

        var entity = new SgtqQueueFrontDetailEntity();
        result = await GetQueue(request);

        if (result.Success)
        {
            entity = (SgtqQueueFrontDetailEntity)result.data;
            await SwitchMsg(entity.User_Id, 1, true);
        }
        else
        {
            result.SetError("数据错误");
            return result;
        }

        var alarmCount = entity.Alarm_Times + 1;

        //if (alarmCount > 3)//超过3次算过期
        //{
        //    await DeleteQueueCode(new DelQueueRequest
        //    {
        //        Id = entity.Id,
        //        Status = 3,
        //    });
        //    result.SetSuccess();
        //    return result;
        //}

        var sql = "UPDATE sgtq_front_queue_detail SET status = 1,alarm_times = @Alarm WHERE Id = @Id";
        var res = await connection.ExecuteAsync(sql, new
        {
            Id = request.Id,
            Alarm = alarmCount,
        });

        if (res == 1)
        {
            result.SetSuccess();
        }
        else
        {
            result.SetError();
        }

        return result;
    }
    public async Task<CommonResponse> Keep(IdRequest request)
    {
        var result = new CommonResponse();

        var entity = new SgtqQueueDetailEntity();
        result = await GetQueue(request);

        if (result.Success)
        {
            entity = (SgtqQueueDetailEntity)result.data;
        }
        else
        {
            result.SetError("数据错误");
            return result;
        }

        var sqlBuilder = new SqlBuilder();
        sqlBuilder.Add("", "Id", request.Id);

        var sql = "UPDATE sgtq_front_queue_detail SET status = 5 WHERE Id = @Id";
        result = await _dateBaseService.ExecuteAsync(sql, sqlBuilder);

        return result;
    }
    public async Task<CommonResponse> GetUser(FrontGetUserRequest request)
    {
        var result = new CommonResponse();

        var client = _httpClientFactory.CreateClient();
        var requestString = $"http://ziyan.xshhotels.cn/wxRtss/wxMp/getUser?code={request.Code}&appId={request.AppId}";
        var response = await client.PostAsync(
            requestString, new StringContent(""));
        if (response.IsSuccessStatusCode)
        {
            var responseStream = await response.Content.ReadAsStreamAsync();

            using (responseStream)
            {
                var res = await ToolHelper.StreamToStringAsync(responseStream);
                var wxRespon = JsonConvert.DeserializeObject<FrontGetUserHttp>(res);
                string userJson = JsonConvert.SerializeObject(wxRespon);
                //_dateBaseService.CreateLog("GetUser", wxRespon.nickname.ToString()+wxRespon.sex.ToString(), "222", 1);
                if (wxRespon != null)
                {
                    var userResponse = new FrontGetUserResponse()
                    {
                        HeadImgUrl = wxRespon.headImgUrl,
                        Nickname = wxRespon.nickname,
                        UserId = AesCbcHelper.Encrypt(wxRespon.openid, System.Text.Encoding.Default.GetBytes("xshAesKey1234567"), System.Text.Encoding.Default.GetBytes("1234567890abcdef")),
                    };
                    //if (wxRespon.sex == 0)
                    //{
                    //    userResponse.Nickname += "先生";
                    //}
                    //else
                    //{
                    //    userResponse.Nickname += "女士";
                    //}
                    result.SetSuccess(userResponse);
                }
                else
                {
                    result.SetError();
                    result.msg = res;
                }
                return result;
            }

        }

        return result;
    }
    public async Task<CommonResponse> SendMsg(FrontWxMpMsgPamRequest request)
    {
        var result = new CommonResponse();

        var client = _httpClientFactory.CreateClient();
        var requestString = $"http://ziyan.xshhotels.cn/wxRtss/wxMp/sendTempMsg";

        var temp = JsonConvert.SerializeObject(request);

        var postContent = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");

        var response = await client.PostAsync(requestString, postContent);
        if (response.IsSuccessStatusCode)
        {
            result.SetSuccess();
        }
        else
        {
            result.SetError();
        }

        return result;
    }
    public async Task<CommonResponse> SwitchMsg(string userId, int type, bool flag = false, PagingQueueFrontResponse request = null)//0取号,1叫号,2过号,6排队报告
    {
        var result = new CommonResponse();

        var requestMsg = new FrontWxMpMsgPamRequest()
        {
            url = "http://ziyan.xshhotels.cn/wxRtss/wxMp/wxQueue/pages/queueFront/queue",
            appId = "wxc06d9725ce3431a2",
            openid = AesCbcHelper.Decrypt(userId, System.Text.Encoding.Default.GetBytes("xshAesKey1234567"), System.Text.Encoding.Default.GetBytes("1234567890abcdef"))
        };

        var entity = new AddQueueFrontResponse();

        if (type != 6)
        {
            var openId = AesCbcHelper.Decrypt(userId, System.Text.Encoding.Default.GetBytes("xshAesKey1234567"), System.Text.Encoding.Default.GetBytes("1234567890abcdef"));

            if (flag == true)
                openId = userId;

            result = await PagingQueueByConsumer(new PagingQueueFrontByConsumerRequest() { UserId = userId });
            if (result.Success)
            {
                entity = (AddQueueFrontResponse)result.data;
            }
            else
            {
                result.SetError();
                return result;
            }
        }

        switch (type)
        {
            case 0:
                requestMsg.templateId = "YoWLZ-fOzpmm4oCwvGYQkiThuG5fCaZCEckxnCdJ9rg";
                requestMsg.msgBody = new Dictionary<string, string>
                {
                    {"thing5",GetName(entity.ShopId)},
                    {"character_string2",entity.Code },
                    { "short_thing3",entity.Num.ToString()+"号"},
                    { "time11",entity.Time.ToString()},
                };
                break;
            case 1:
                requestMsg.templateId = "wx6gOUgxgmhZrqV0FMiFB51xx94qgN0FejP0DxQQMLo";
                requestMsg.msgBody = new Dictionary<string, string>
                {
                    { "character_string1",entity.Code},
                    {"thing3",GetName(entity.ShopId)},
                    { "time4",DateTime.Now.ToString()},
                };
                break;
            case 3:
                requestMsg.templateId = "cBA8ZrX_t2Ru0K0GL2ud8IN9nF8P2LA0GFwN068aTOQ";
                requestMsg.msgBody = new Dictionary<string, string>
                {
                    { "character_string2",entity.Code},
                    {"time3",DateTime.Now.ToString()},
                    { "thing1",GetName(entity.ShopId)},
                };
                break;
            case 6://用于普通排队提醒
                requestMsg.templateId = "YoWLZ-fOzpmm4oCwvGYQkiThuG5fCaZCEckxnCdJ9rg";
                requestMsg.msgBody = new Dictionary<string, string>
                {
                    {"thing5",GetName(request.ShopId)},
                    {"character_string2",request.Code },
                    { "short_thing3",request.FrontCount.ToString()+"号"},
                    { "time11",request.CreatedOn.ToString()},
                };
                break;

        }
        requestMsg.url += $"?shopId={entity.ShopId}&shopName={GetName(entity.ShopId)}";
        result = await SendMsg(requestMsg);

        return result;
    }
    /// <summary>
    /// 检查是否关注公众号待定，需要hty进行开发
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    public async Task<CommonResponse> CheckFollowStatus(IdRequest request)
    {
        var result = new CommonResponse();

        request.Id = AesCbcHelper.Decrypt(request.Id, System.Text.Encoding.Default.GetBytes("xshAesKey1234567"), System.Text.Encoding.Default.GetBytes("1234567890abcdef"));

        var client = _httpClientFactory.CreateClient();
        var requestString = $"http://ziyan.xshhotels.cn/wxRtss/wxMp/getUserInfo?openid={request.Id}&appId=wxc06d9725ce3431a2";
        var response = await client.PostAsync(requestString, new StringContent(""));

        if (response.IsSuccessStatusCode)
        {
            var responseStream = await response.Content.ReadAsStreamAsync();

            using (responseStream)
            {
                var res = await ToolHelper.StreamToStringAsync(responseStream);
                var temp = JsonConvert.DeserializeObject<FrontWxIsFollowResponse>(res);
                if (temp != null)
                {
                    result.SetSuccess(temp);
                }
            }

        }

        return result;
    }
    public string GetName(string pmsId)
    {
        var result = string.Empty;

        switch (pmsId)
        {
            case "xshqs01":
                return "北京曲水";
                break;
            case "xshqs02":
                return "武汉曲水1店";
                break;
            case "xshqs03":
                return "杭州曲水";
                break;
            case "xshqs04":
                return "武汉曲水2店";
                break;
            case "xshqs05":
                return "苏州曲水";
                break;
            case "xshqs06":
                return "上海曲水";
                break;
            case "xshqs07":
                return "郑州曲水";
                break;
            case "xshsg01":
                return "上海水裹虹桥店";
                break;
            case "xshsg02":
                return "上海水裹2店";
                break;
            case "xshsg03":
                return "北京水裹";
                break;
            case "xshsg04":
                return "北京水裹加";
                break;
            case "xshsg05":
                return "杭州水裹1店";
                break;
            case "xshsg06":
                return "杭州水裹2店";
                break;
            case "xshsg07":
                return "武汉水裹";
                break;
            case "xshsg08":
                return "常州水裹";
                break;
            case "xshsg09":
                return "深圳水裹";
                break;
        }

        return result;
    }
}